import { createReadStream } from "fs";
// import { createReadStream } from "./ReadStream.js";
import path from "path";
//   node 20+
const rs = createReadStream(path.resolve(import.meta.dirname, "1.txt"), {
  highWaterMark: 4,
  emitClose: true,
  start: 0,
  end: 10, // 11个字节
  flags: "r",
});

// {open:[fn],data:[fn]}
rs.on("open", function (fd) {
  console.log("open", fd);
});
rs.on("data", function (chunk) {
  console.log(chunk)
  rs.pause()
});

rs.on("end", function () {
  console.log("end");
});

rs.on("close", function () {
  console.log("close");
});

rs.on("error", function (err) {
  console.log("error", err);
});

setInterval(() => {
  rs.resume();
}, 1000)